# -*- coding: utf-8 -*-
# author yzs
# date 2019-01-01
#
# 最长公共子序列
# Description
# 给定两个字符串，返回两个字符串的最长公共子序列(不是最长公共子字符串)，可能多个
# Input
# 输入为两行，一行一个字符串
# Output
# 输出如果有多个则分多行，先后顺序不影响判断
# Sample Input 1
# 1A2BD3G4H56JK
# 23EFG4I5J6K7
# Sample Output 1
# 23G456K
# 23G45JK


def lcs(str1, str2, dp, flag):
    # 填充矩阵
    for i in range(len(str1) + 1):
        for j in range(len(str2) + 1):
            # 相等的情况
            if str1[i - 1] == str2[j - 1]:
                dp[i][j] = dp[i - 1][j - 1] + 1
                flag[i][j] = "left_up"
            else:
                # 比较“左边”和“上边“，根据其max来填充
                if dp[i - 1][j] >= dp[i][j - 1]:
                    dp[i][j] = dp[i - 1][j]
                    flag[i][j] = "left"
                else:
                    dp[i][j] = dp[i][j - 1]
                    flag[i][j] = "up"


def print_sequence(i, j, data, result):
    if i <= 0 and j <= 0:
        return
    if flag[i][j] == "left_up":
        result.append(data[j - 1])
        print_sequence(i - 1, j - 1, data, result)
    else:
        if flag[i][j] == "up":
            if flag[i-1][j] == "left_up":
                flag[i][j] = "left"
            print_sequence(i, j - 1, data, result)
        else:
            if flag[i][j-1] == "left_up":
                flag[i][j] = "up"
            print_sequence(i - 1, j, data, result)


while True:
    try:
        data_a = input().strip()
        data_b = input().strip()
        data_a_len, data_b_len = len(data_a), len(data_b)
        dp = [[0 for i in range(data_b_len + 1)] for j in range(data_a_len + 1)]
        flag = [[0 for i in range(data_b_len + 1)] for j in range(data_a_len + 1)]
        lcs(data_a, data_b, dp, flag)
        # for i in range(data_a_len+1):
        #     print(dp[i])
        # for i in range(data_a_len+1):
        #     print(flag[i])
        result1 = []
        print_sequence(data_a_len, data_b_len, data_b, result1)
        result1.reverse()
        print("".join(str(i) for i in result1))
        result2 = []
        print_sequence(data_a_len, data_b_len, data_b, result2)
        result2.reverse()
        if result1 != result2:
            print("".join(str(i) for i in result2))
    except EOFError:
        break
